package com.ambow.fw;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileRWDemo {
	public static void writer() throws IOException{
		BufferedWriter bw=new BufferedWriter(new FileWriter("data.txt"));
		for(int i=1;i<100;i++){
			Student t=new Student();
			t.setAge(10);
			t.setBirthday(new Date());
			t.setId(i);
			t.setName("test"+i);
			bw.write(t.toString());
			bw.newLine();
		}
		bw.flush();
		bw.close();
	}
	
	public static void reader() throws IOException{
		BufferedReader br=new BufferedReader(new FileReader("data.txt"));
		String str=null;
		while((str=br.readLine())!=null){
			if("".equals(str.trim())){
			}else{
				String[] ss=str.split(",");
				Student t=new Student();
				t.setAge(Integer.valueOf(ss[2]));
				t.setId(Integer.valueOf(ss[0]));
				t.setName(ss[1]);
				DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
				try {
					Date dt=df.parse(ss[3]);
					t.setBirthday(dt);
				} catch (ParseException e) {
					e.printStackTrace();
				}
				System.out.println(t);
				System.out.println(t);
				System.out.println(t);
				System.out.println(t);
			}
		}
		br.close();
	}
	
}
